package com.lbd.gulimall.ware.interceptor;

import com.lbd.common.constrant.CommonAuthConstrant;
import com.lbd.common.to.MemberEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: linbd
 * @Description:
 * @Date: 2023/3/23 22:13
 */
@Slf4j
@Component
public class WareInterceptor implements HandlerInterceptor {
    public static ThreadLocal<MemberEntity> onlineUser = new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        MemberEntity member = (MemberEntity) request.getSession().getAttribute(CommonAuthConstrant.LOGIN_USER);
        if (member != null) {
            onlineUser.set(member);
            return true;
        } else {
            request.getSession().setAttribute("orderErrMsg","查询运费需要登录...");
            response.sendRedirect("http://auth.gulimall.com/login.html");
            return false;
        }
    }
}
